from ckeditor_uploader.fields import RichTextUploadingField
from django.db import models




class Address(models.Model):
    # 表字段
    aname = models.CharField('地点', max_length=20, null=False)
    def __str__(self):
        return '%s'%(self.aname,)

    class Meta:
        db_table = '地点管理'
        verbose_name = '地点管理'
        verbose_name_plural = verbose_name


class Lable(models.Model):
    lname = models.CharField('标签名称', max_length=20, null=False)

    def __str__(self):
        return '%s'%(self.lname,)

    class Meta:
        db_table = '标签管理'
        verbose_name = '标签管理'
        verbose_name_plural = verbose_name


# 旅游景点
class TourName(models.Model):
    title = models.CharField(verbose_name="标题", max_length=50)# 标题
    text = models.CharField('摘要', max_length=200, default='没有简介')
    body = RichTextUploadingField('正文')
    photo = models.ImageField(verbose_name="缩略图",upload_to="static/images/")
    address = models.ForeignKey(Address, on_delete=models.CASCADE,verbose_name="地点")  # 分类
    lable = models.ForeignKey(Lable, on_delete=models.CASCADE, verbose_name='标签') # 标签
    created = models.DateTimeField(verbose_name="发表时间",auto_now_add=True) #设置模型对象第一次创建时的系统时间
    updated = models.DateTimeField(verbose_name="更新时间",auto_now=True) #每次修改model，都会自动更新
    readnum = models.PositiveIntegerField(default=0)
    likenum = models.PositiveIntegerField(default=0)

    def __str__(self):
        return '%s-%s-%s-%s-%s-%s-%s'%(self.title, self.body, self.photo , self.address, self.lable, self.created, self.updated)

    class Meta:
        db_table = '旅游景点管理'
        verbose_name = '旅游景点管理'
        verbose_name_plural = verbose_name

class Img(models.Model):
    # 表字段
    img = models.ImageField(verbose_name="缩略图",upload_to="static/images/")
    def __str__(self):
        return '%s'%(self.img,)

    class Meta:
        db_table = '首页图片管理'
        verbose_name = '首页图片管理'
        verbose_name_plural = verbose_name

